package com.lhx.product.controller;

import com.lhx.common.core.domain.R;
import com.lhx.product.domain.dto.BrandDTO;
import com.lhx.product.domain.po.BrandPO;
import com.lhx.product.result.PageResult;
import com.lhx.product.result.Result;
import com.lhx.product.domain.vo.BrandVO;

import com.lhx.product.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author：lihongxiang
 * @Package：com.lhx.product.controller
 * @Project：lhx-RuoYi
 * @name：BrandController
 * @Date：2024/5/22 下午8:36
 */
@RestController
@RequestMapping("/brand")
@Api(tags = "品牌管理模块")
public class BrandController {

    @Autowired
    private BrandService brandService;


    /**
     * 添加品牌表
     * @param brandPO
     * @return
     */
    @ApiOperation(value = "添加品牌表")
    @PostMapping("/addBrand")
    public Result<BrandPO> addBrand(@Valid @RequestBody BrandPO brandPO){
        Integer i=brandService.addBrand(brandPO);
        return i>0?Result.success(brandPO,"添加成功"):Result.error("添加失败");
    }

    /**
     * 查询品牌列表
     * 分页查询
     * 模糊查询
     * @param brandDTO
     * @return
     */
    @ApiOperation(value = "查询品牌列表信息")
    @PostMapping("/findBrandList")
    public Result<PageResult<BrandVO>> findBrandList(@RequestBody BrandDTO brandDTO){
        return brandService.findBrandList(brandDTO);
    }

    /**
     * 修改品牌信息
     * @param brandPO
     * @return
     */
    @ApiOperation(value = "修改品牌表")
    @PostMapping("/updateBrand")
    public Result<BrandPO> updateBrand(@Valid @RequestBody BrandPO brandPO){
        Integer i=brandService.updateBrand(brandPO);
        return i>0?Result.success(brandPO,"修改成功"):Result.error("修改失败");
    }

    @ApiOperation(value = "测试")
    @PostMapping("/ce")
    public void ce(){

    }

    /**
     * 删除品牌信息
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除品牌表")
    @PostMapping("/deleteBrand")
    public Result<BrandPO> deleteBrand(@RequestBody Integer[] ids){
        Integer i=brandService.deleteBrand(ids);
        return i>0?Result.success(null,"删除成功"):Result.error("删除失败");
    }

    /**
     * 批量操作
     * 批量删除品牌信息
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除品牌表")
    @PostMapping("/delete/batch")
    public R deleteBatch(@RequestBody List<Long> ids) {
        int flag=brandService.deleteBatch(ids);
        return flag>0?R.ok(ids,"批量删除成功"):R.fail();
    }

    /**
     * 批量更新显示状态
     * @param ids
     * @param showStatus
     * @return
     */

    @ApiOperation(value = "批量更新显示状态")
    @PostMapping(value = "/updateShowStatus")
    public Result updateShowStatus(@RequestParam("ids") List<Long> ids,
                                         @RequestParam("showStatus") Integer showStatus) {
        int flag = brandService.updateShowStatus(ids, showStatus);
        return flag>0?Result.success("修改成功"):Result.error("修改失败");
    }


    /**
     * 批量更新厂家制造商状态
     * @param ids
     * @param factoryStatus
     * @return
     */
    @ApiOperation(value = "批量更新厂家制造商状态")
    @PostMapping(value = "/updateFactoryStatus")
    public Result updateFactoryStatus(@RequestParam("ids") List<Long> ids,
                                   @RequestParam("factoryStatus") Integer factoryStatus) {
        int flag = brandService.updateFactoryStatus(ids, factoryStatus);
        return flag>0?Result.success("修改成功"):Result.error("修改失败");
    }

    /**
     * 根据id查询品牌信息
     * @param id
     * @return
     */
    @PostMapping("/findBrandById")
    public Result<BrandVO> findBrandById(@RequestParam("id") Integer id){
        BrandVO brandVO=brandService.findBrandById(id);
        return brandVO!=null?Result.success(brandVO,"查询成功"):Result.error("查询失败");
    }






}
